package chapter2;

/**
 * @author Hang
 * @date 2022/8/10
 * @project AutumnOffer
 * @description 面试题11
 **/
public class minArray {
    public static void main(String[] args) {
        int[] nums = new int[]{3,4,5,1,2};
        System.out.println(minArray(nums));
    }
    public static int minArray(int[] numbers) {
        int low = 0,high = numbers.length - 1; //定义访问边界
        while(low < high){ // 不需要相等
            int mid = (high - low)/2+low; // 求中间节点
            if(numbers[mid] > numbers[high]){ // 如果大于右边，则在mid+1，high
                low = mid + 1;
            }else if(numbers[mid] < numbers[high]){ // 如果小于，则在low，mid
                high = mid;
            }else{
                high = high - 1;// 否则high-1
            }
        }
        return numbers[low];
    }
}
